<template>
    <view class="content">
        <view class="area-box">
            <textarea maxlength="100" v-model="content" :placeholder="placeholder"></textarea>
        </view>
        <div class="common-btn">
            <button class="cu-btn block bg-green margin-tb-sm lg" @click="submit">保存</button>
        </div>
    </view>
</template>

<script>
    import api from '@/api/api.js';
    export default {
        data() {
            return {
                item: '',
                content: '',
                status: '',
                placeholder: '请输入备注(选填)'
            }
        },
        onLoad(o) {
            this.item = this.getS(`activeCustomerDetail`)
            this.type = o.type
            if (o.type == '邀约成功') {
                this.status = 3
                this.placeholder = '请输入备注(选填)'
            }
            if (o.type == '邀约失败') {
                this.status = 2
                this.placeholder = '请输入邀约失败原因(必填)'
            }
            if (o.type == '拒传征信') {
                this.placeholder = '请输入拒传征信原因(必填)'
            }
            if (o.type == '拒签合同') {
                this.placeholder = '请输入拒签合同原因(必填)'
            }
            if (o.type == '执行失败') {
                this.placeholder = '请输入执行失败原因(必填)'
            }

            // 修改顶部导航背景色
            uni.setNavigationBarColor({
                frontColor: '#ffffff',
                backgroundColor: '#39b54a',
                animation: {
                    duration: 400,
                    timingFunc: 'easeIn'
                }
            })
        },
        methods: {
            submit() {
                if (this.type != '邀约成功' && !this.content) return this.toast(this.placeholder)
                if (this.type == '邀约成功') this.fn1()
                if (this.type == '邀约失败') this.fn1()
                if (this.type == '拒传征信') this.fn3()
                if (this.type == '拒签合同') this.fn4()
                if (this.type == '执行失败') this.fn5()
            },
            fn1() { //邀约
                var data = { customerId: this.item.customerId, status: this.status, refuseMsg: this.content }
                api.invitation(data).then(
                    res => {
                        if (res.code == 200) {
                            uni.showToast({
                                title: '提交成功',
                                duration: 2000
                            });
                            setTimeout(function() {
                                uni.navigateBack({
                                    success: () => {}
                                })
                            }, 500);
                        } else {
                            uni.showToast({
                                title: res.msg,
                                icon: 'none',
                            });
                        }

                    },
                    rej => {}
                );
            },
            fn3() { //拒传征信
                var data = {
                    "crmCreInvId": this.item.crmCreInvId,
                    "isCreInvStatus": 4,
                    "refuseMsg": this.content
                }
                api.isCreInv(data).then(
                    res => {
                        if (res.code == 200) {
                            uni.showToast({
                                title: '提交成功',
                                duration: 2000
                            });
                            setTimeout(function() {
                                uni.navigateBack({
                                    success: () => {}
                                })
                            }, 500);
                        } else {
                            uni.showToast({
                                title: res.msg,
                                icon: 'none',
                            });
                        }

                    },
                    rej => {}
                );
            },
            fn4() { //拒签合同
                var data = {
                    customerContractId: this.item.customerContractId,
                    isContractStatus: 6,
                    refuseMsg: this.content
                }
                api.isContract(data).then(
                    res => {
                        if (res.code == 200) {
                            uni.showToast({
                                title: '提交成功',
                                duration: 2000
                            });
                            setTimeout(function() {
                                uni.navigateBack({
                                    success: () => {}
                                })
                            }, 500);
                        } else {
                            uni.showToast({
                                title: res.msg,
                                icon: 'none',
                            });
                        }

                    },
                    rej => {}
                );
            },
            fn5() { //执行失败
                var data = {
                    cstomerId: this.item.customerId,
                    impStatus: 0,
                    refuseMsg: this.content,
                    impId: this.item
                        .impId
                }
                api.impEdit(data).then(
                    res => {
                        if (res.code == 200) {
                            uni.showToast({
                                title: '提交成功',
                                duration: 2000
                            });
                            setTimeout(function() {
                                uni.navigateBack({
                                    success: () => {}
                                })
                            }, 500);
                        } else {
                            uni.showToast({
                                title: res.msg,
                                icon: 'none',
                            });
                        }

                    },
                    rej => {}
                );
            },
        }
    }
</script>

<style lang="scss">
    page {
        height: 100%;
    }

    .content {
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: space-between;

        .area-box {
            margin-top: 20upx;
            padding: 20upx 24upx;
            background: #fff;

            textarea {
                width: 100%;
                height: 200upx;
                border: 1px solid #f7f7f7;
                border-radius: 8upx;
                padding: 20upx;
            }
        }

    }
</style>